﻿using System;
using System.IO;

namespace WebShopDAL
{
    public class KlauserSwagException : ApplicationException
    {
        public KlauserSwagException(string message, Exception innerException)
            : base(message, innerException)
        {
            WriteExceptionToFile(message, innerException);
        }
        private void WriteExceptionToFile(string message, Exception innerMessage)
        {
            try
            {
                using (var streamWriter = new StreamWriter(@"~/ExceptionLog.txt", true))
                {
                    streamWriter.WriteLine(DateTime.Now.ToString(), message, innerMessage.InnerException);
                }
            }
            catch (Exception ex)
            {
                throw new KlauserSwagException("Writing exception to file failed!", ex);
            }
        }
    }
}
